package com.dc.chat.controller;

import com.dc.chat.app.biz.FriendApplyBiz;
import com.dc.chat.app.service.mp.FriendApplyService;
import com.dc.chat.entity.dao.FriendApply;
import com.dc.chat.entity.to.ResponseBean;
import com.dc.chat.entity.to.friendApply.AddFriendApplyReq;
import com.dc.chat.interceptor.security.Security;
import com.fasterxml.jackson.core.JsonProcessingException;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/friendApply")
public class FriendApplyController {
    @Resource
    FriendApplyBiz friendApplyBiz;
    @PostMapping("/add")
    @Security
    public ResponseBean<Integer> addFriendApply(@Validated @RequestBody AddFriendApplyReq req){
        return friendApplyBiz.addFriendApply(req.getUserId(),req.getContext());
    }
    @PostMapping("/getList")
    @Security
    public ResponseBean<List<FriendApply>> getList(){
        return friendApplyBiz.getList();
    }
    @PostMapping("/agree")
    @Security
    public ResponseBean<Integer> agree(@RequestParam("id") Integer id) throws JsonProcessingException {
        return friendApplyBiz.agree(id);
    }
    @PostMapping("/reject")
    @Security
    public ResponseBean<Integer> reject(@RequestParam("id") Integer id){
        return friendApplyBiz.reject(id);
    }
}
